#!/usr/bin/python
from operator import itemgetter, attrgetter

class unit:
    def __init__(self, id, pv, totalcomment, fav, up, down, reference):
        self.id = id
        self.pv = pv
        self.totalcomment = totalcomment
        self.fav = fav
        self.up = up
        self.down = down
        self.reference = reference
        self.score = 0
    def calcScore(self):
        self.score = self.reference

limit = 0.002
reader = open('2011-12-05.stat', 'r')
id = ""
pv = 0
totalcomment = 0
fav = 0
up = 0
down = 0
reference = 0
l = []
while True:
    line = reader.readline()
    if line == "":
        break
    if line[0] == 'i':
        id = line[4:-1]
        continue
    if line[0] == 'p':
        pv = int(line[4:-1])
        continue
    if line[0] == 't':
        totalcomment = int(line[14:-1])
        continue
    if line[0] == 'f':
        fav = int(line[5:-1])
        continue
    if line[0] == 'u':
        up = int(line[4:-1])
        continue
    if line[0] == 'd':
        down = int(line[6:-1])
        continue
    if line[0] == 'r':
        reference = int(line[11:-1])
        u = unit(id, pv, totalcomment, fav, up, down, reference)
        u.calcScore()
        l.append(u)
count = int(limit * len(l))
ol = sorted(l, key=attrgetter('score'), reverse=True)
for i in ol:
    #    if i.score >= 20:
    print i.id, '\t', i.up, '\t', i.down, '\t', i.score
reader.close()
